{include file='public/header' /}
<style>
    .edui-dialog-image-body{
        height: 220px!important;
        overflow: hidden;
    }
    .edui-dialog-image .edui-image-wrapper{
        box-sizing: border-box;
        height: 100%;
    }
    .edui-tab-nav{
        height:43px;
    }
    .edui-dialog-image .edui-image-content {
        height: 200px!important;
    }
    #demo2{
        display: flex;
        align-items: center;
    }
    #demo2 li .operate{ color: #000; display: none;}
    #demo2 li .close{position: absolute;top: 5px; right: 5px;cursor:pointer;}
    #demo2 li:hover .operate{ display: block;}
    .operate{
        position: absolute;
        right: 0;
        top: -9px;
        color: black;
        font-size: 34px;
        /* border: 1px solid red; */
        font-weight: bold;
    }
    .item_img{
        position: relative;margin-right: 10px;
    }
    .attribute{
        width: 90%;
        border: 1px solid #e6e6e6;
        margin-top:20px;
    }
    .atr{
        height: 50px;
        border: 1px solid #e6e6e6;
    }
    .ath{
        width: 100px; border-left: 1px solid #e6e6e6; border-right: 1px solid #e6e6e6;
    }
    .atd{
        display: flex;
        text-align: center;
        height: 38px;
        justify-content: center;
        align-items: center;
    }
    table input{
        text-align: center;
        border: none!important;
    }
    table td{
        border-right: 1px solid #e6e6e6;
        border-bottom: 1px solid #e6e6e6;
    }
    table td:last-child{
        border-right: none;
    }
</style>
<div class="layuimini-container">
    <form id="modelUserForm" lay-filter="modelUserForm" class="layui-form model-form">
        <input name="id" type="hidden" value="{$row.id}"/>

        <div class="layui-form-item">
            <label for="" class="layui-form-label">教师名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" maxlength="8" value="{$row.name}"  lay-verify="required" placeholder="请输入教师名称，最多输入8个字" class="layui-input" >
            </div>
        </div>

        <div class="layui-form-item">
            <label for="" class="layui-form-label">头像</label>
            <div class="layui-input-block">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-sm uploadPic"><i class="layui-icon">&#xe67c;</i>图片上传</button>
                    <div class="layui-upload-list" >
                        <ul class="layui-upload-box layui-clear">
                            <li><img style="width:100px;height: 60px;" src="{$row.thumb}" /></li>
                        </ul>
                        <input type="hidden" name="thumb" class="layui-upload-input" value="{$row.thumb}">
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="" class="layui-form-label">毕业院校</label>
            <div class="layui-input-block">
                <input type="text" name="school" maxlength="20" value="{$row.school}"  lay-verify="required" placeholder="请输入毕业院校，最多输入20个字" class="layui-input" >
            </div>
        </div>

        <div class="layui-upload" style="margin: 20px 0;">
            <label class="layui-form-label">授课</label>

            <button type="button" class="layui-btn" id="attribute"><i class="layui-icon"></i>添加授课</button>
            <table class="attribute" style="margin-top: 10px;margin-left: 110px;">
                <tr class="atr">
                    <th style="width: 200px;text-align:center">授课名称</th>
                    <th style="width: 80px;text-align:center">操作</th>
                </tr>
                {notempty name="$row.teaching"}
                {foreach $row.teaching as $k=>$v}
                <tr>
                    <td>
                        <input type='text' name='teaching[]' lay-verify='required' placeholder='授课名称，最多5个字' maxlength='5'
                               class='layui-input sl' value="{$v}">
                    </td>
                    <td style="text-align: center">
                        <a href='javascript:;'class='layui-btn layui-btn-xs layui-btn-primary delete'  style='margin-right: 0;font-size:12px;'><span><i class='layui-icon'></i></span></a>
                    </td>
                </tr>
                {/foreach}
                {/notempty}

            </table>
        </div>


        <div class="layui-form-item">
            <label for="" class="layui-form-label">教师介绍</label>
            <div class="layui-input-block">
                <textarea name="introduce" lay-verify="content" style="width: 980px;height: 150px;"  class="field-content" id="">{$row.introduce}</textarea>
                <!--<script id="container" name="introduce" type="text/plain" style="width: 1000px;height:300px;">{$row.introduce|raw}</script>-->
                <p> <span style="color: grey ">字数限制300字</span></p>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="" class="layui-form-label">平台备注</label>
            <div class="layui-input-block">
                <textarea   placeholder="请输入备注"  readonly  class="layui-textarea">{$row.remarks}</textarea>
            </div>
        </div>
        <div class="layui-form-item text-left">
            <label for="" class="layui-form-label"></label>
            <button class="layui-btn" lay-filter="modelSubmitUser" lay-submit>保存</button>
        </div>
    </form>
</div>
{include file='public/footer' /}
<script>
    layui.use(['layer', 'form', 'table', 'util', 'admin','upload'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        var upload = layui.upload;

        var url = '{:__url("business.organ_teacher/edit")}';

        // 表单提交事件
        form.on('submit(modelSubmitUser)', function (data) {
            var content = $('#container').text();
            var contents = content.replace(/[\r\n]/g,"");
//            console.log(contents);
//            console.log(contents.length);
            if(contents.length>300){
                layer.msg('教师介绍不能超过300个字', {icon: 2});
                return false;
            }

            $.post(url, data.field, function (res) {

                layer.closeAll('loading');
                if (res.code == 1) {
                    layer.msg(res.msg, {icon: 1,time: 1000},function(index){
                        window.parent.location.reload();
                    });
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'json');
            return false;
        });

        //普通图片上传
        $(".uploadPic").each(function (index,elem) {
            upload.render({
                elem: $(elem)
                ,url: '{:__url("admin/upload/upload")}'
                ,multiple: false
                ,data:{"_token":"{{ csrf_token() }}"}
                ,done: function(res){
                    //如果上传失败
                    if(res.code == 0){
                        layer.msg(res.msg,{icon:1,time:1000},function () {
                            $(elem).parent('.layui-upload').find('.layui-upload-box').html('<li><img style="width:100px;height: 60px;" src="'+res.url+'" /></li>');
                            $(elem).parent('.layui-upload').find('.layui-upload-input').val(res.url);
                        })
                    }else {
                        layer.msg(res.msg,{icon:2,time:1000})
                    }
                }
            });
        })

//添加课时目录
        $('#attribute').click(function(){
            $(".attribute").append("<tr>"+"<td><input type='text' name='teaching[]' lay-verify='required' placeholder='授课名称，最多5个字' maxlength='5' class='layui-input sl' ></td>" +
                    "<td style='text-align: center'><a href='javascript:;'class='layui-btn layui-btn-xs layui-btn-primary delete'  style='margin-right: 0;font-size:12px;'><span><i class='layui-icon'></i></span></a></td>"+"</tr>");

        })
        form.render('checkbox');
        $(document).on("click","span",function () {
            $(this).parents('tr').remove();
        })
    });

</script>
<link href="/baidu-editor/themes/default/css/umeditor.min.css" type="text/css" rel="stylesheet">
<script src="/baidu-editor/third-party/jquery.min.js"></script>
<!-- 配置文件 -->
<script type="text/javascript" src="/baidu-editor/umeditor_teacher.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="/baidu-editor/umeditor.min.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UM.getEditor('container');
</script>